module.exports = (sequelize, Sequelize) => {
  const Comment = sequelize.define('comment', {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    content: {
      type: Sequelize.TEXT,
      allowNull: false,
      validate: {
        notEmpty: true
      }
    },
    userId: {
      type: Sequelize.INTEGER,
      allowNull: false,
      references: {
        model: 'users',
        key: 'id'
      }
    },
    postId: {
      type: Sequelize.INTEGER,
      allowNull: false,
      references: {
        model: 'posts',
        key: 'id'
      }
    },
    parentId: {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: {
        model: 'comments',
        key: 'id'
      }
    },
    status: {
      type: Sequelize.ENUM('approved', 'pending', 'spam'),
      defaultValue: 'pending'
    }
  }, {
    timestamps: true,
    paranoid: true, // 软删除
    indexes: [
      {
        fields: ['userId']
      },
      {
        fields: ['postId']
      },
      {
        fields: ['parentId']
      }
    ]
  });

  return Comment;
};